package com.tlcx.kfip.utils;

import android.content.Context;

import com.tlcx.kfip.BaseApplication;

/**
 * 作者：Longfei Yang on 2015/9/2 09:26
 * 邮箱：yanglongfei@yuanchuangyun.com
 */
public class PreferencesManager {
    private Context context;

    public PreferencesManager(){}

    public PreferencesManager(Context con){
        context = con;
    }

    public <T> void commonSave(String key, T t){
        save(null, key, t);
    }

    /*public <T> void userSave(String key, T t){
        if (Constants.getUserInfo() != null){
            String userFileName = Constants.getUserInfo().getId();
            save(userFileName, key, t);
        }
    }*/

    private <T> void save(String fileName, String key,  T t){
        if(null == context){
            context = BaseApplication.getAPPContext();
        }
        SpUtil.saveToLocal(context, fileName, key, t);
    }

    public <T> T commonGet(String key, T defaultValue){
        return get(null, key, defaultValue);
    }

    /*public <T> T userGet(String key, T defaultValue){
        if (Constants.getUserInfo()!=null){
            String userFileName = Constants.getUserInfo().getId();
            return get(userFileName, key, defaultValue);
        }
        return defaultValue;
    }*/

    private <T> T get(String fileName, String key, T t){
        if(null == context){
            context = BaseApplication.getAPPContext();
        }
        return SpUtil.getFromLocal(context, fileName, key, t);
    }
}
